package com.example.javamaday.encrypt_decrypt;

import android.support.annotation.RequiresApi;

import java.security.MessageDigest;
import java.util.Base64;

public class DigestDemo {

    @RequiresApi(api = 26)
    public static void main(String[] args) throws Exception {
        String input = "MaoMao";
        MessageDigest messageDigest = MessageDigest.getInstance("MD5");
        byte[] digest = messageDigest.digest(input.getBytes());

        System.out.println(new java.lang.String(Base64.getEncoder().encode(digest)));

        for (byte b : digest) {
            // 把密文转为16进制
            String s = Integer.toHexString(b & 0xFF);
            if (s.length() == 1) {
                s = "0" + s;
            }
            System.out.print(s);
        }
    }
}
